{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The goal of this section is to be able to __deepcopy__ sexp objects and load them quickly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-04-06T15:33:25.393377Z",
     "start_time": "2019-04-06T15:33:25.372904Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import os\n",
    "from pykicad import Module\n",
    "import pykicad\n",
    "import copy\n",
    "\n",
    "footprint_library_location = './'\n",
    "os.environ['KISYSMOD'] = os.pathsep + footprint_library_location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-04-06T15:33:26.271382Z",
     "start_time": "2019-04-06T15:33:26.251927Z"
    }
   },
   "outputs": [],
   "source": [
    "# First component load. Doesn't use cache\n",
    "r1 = Module.from_library('testlib', 'TLC5955')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-04-06T15:33:26.843281Z",
     "start_time": "2019-04-06T15:33:26.823811Z"
    }
   },
   "outputs": [],
   "source": [
    "# Scond component load. Should be much faster.\n",
    "r1 = Module.from_library('testlib', 'TLC5955')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-04-06T15:33:27.864858Z",
     "start_time": "2019-04-06T15:33:27.579414Z"
    }
   },
   "outputs": [],
   "source": [
    "# Clearing cache\n",
    "Module.clear_cache()\n",
    "\n",
    "# Load again. Should be slower.\n",
    "r1 = Module.from_library('testlib', 'TLC5955')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Deep Copy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-04-06T15:35:02.710104Z",
     "start_time": "2019-04-06T15:35:02.415689Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0, 0)\n",
      "(10, 10)\n"
     ]
    }
   ],
   "source": [
    "# Clearing cache\n",
    "Module.clear_cache()\n",
    "\n",
    "# Load again. Should be slower.\n",
    "r1 = Module.from_library('testlib', 'TLC5955')\n",
    "r1.at = (0,0)\n",
    "print(r1.at)\n",
    "r2 = copy.deepcopy(r1)\n",
    "\n",
    "r2.at = (10,10)\n",
    "print(r2.at)\n",
    "\n",
    "assert r1.at[0] != r2.at[0]\n",
    "assert r1.at[1] != r2.at[1]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
